package thread;

//单例模式--饿汉式-尽早创建实例
class Singleton {

    private static Singleton instance = new Singleton();

    public static Singleton getInstance() {
        return instance;
    }

    private Singleton() {//构造方法必须是private

    }

}

public class Demo27 {

    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);//true

//        Singleton s3 = new Singleton();//无法创建新的对象

    }
}
